local skill = fk.CreateSkill {
  name = "lb__kansha_fire_attack_skill",
}

Fk:loadTranslationTable {
  ["lb__kansha_fire_attack_skill"] = "火攻",
  ["#lb__kansha_fire_attack-show"] = "%src 对 %dest 使用了火攻，请你展示 %dest 一张手牌",
  ["#lb__kansha_fire_attack-discard"] = "你可选择 %src 一张 %arg 手牌令其弃置，对 %dest 造成1点火属性伤害",
}

skill:addEffect("cardskill", {
  prompt = "#fire_attack_skill",
  target_num = 1,
  mod_target_filter = function(self, _, to_select, _, _, _)
    return not to_select:isKongcheng()
  end,
  target_filter = Util.CardTargetFilter,
  on_effect = function(self, room, effect)
    local from = effect.from
    local to = effect.to
    if to:isKongcheng() then return end
    effect.extra_data = effect.extra_data or {}
    local player = effect.extra_data.lb__kansha_fire_attack and
        room:getPlayerById(effect.extra_data.lb__kansha_fire_attack) or nil

    local params = { ---@type AskToCardsParams
      min_num = 1,
      max_num = 1,
      include_equip = false,
      skill_name = skill.name,
      cancelable = false,
      pattern = ".|.|.|hand",
      prompt = "#fire_attack-show:" .. from.id
    }
    local showCard
    if player and player:isAlive() then
      showCard = room:askToChooseCard(player, {
        target = to,
        flag = { card_data = { { to:__touistring(), to:getCardIds("h") } } },
        skill_name = skill.name,
        prompt = "#lb__kansha_fire_attack-show:" .. from.id .. ":" .. to.id,
      })
    else
      showCard = room:askToCards(to, params)[1]
    end
    to:showCards(showCard)

    showCard = Fk:getCardById(showCard)
    params = { ---@type AskToDiscardParams
      min_num = 1,
      max_num = 1,
      include_equip = false,
      skill_name = skill.name,
      cancelable = true,
      pattern = ".|.|" .. showCard:getSuitString(),
      prompt = "#fire_attack-discard:" .. to.id .. "::" .. showCard:getSuitString()
    }
    local cards = {}
    if player and player:isAlive() and not from:isKongcheng() then
      cards = room:askToPoxi(player, {
        poxi_type = skill.name,
        cancelable = true,
        data = { { from:__touistring(), from:getCardIds("h") } },
        extra_data = {
          suit = showCard.suit,
          prompt = "#lb__kansha_fire_attack-discard:" .. from.id .. ":" .. to.id .. ":" .. showCard:getSuitString(),
        }
      })
      if #cards > 0 then
        room:throwCard(cards, skill.name, from, from)
      end
    else
      cards = room:askToDiscard(from, params)
    end
    if #cards > 0 and not to.dead then
      room:damage({
        from = from,
        to = to,
        card = effect.card,
        damage = 1,
        damageType = fk.FireDamage,
        skillName = skill.name,
      })
    end
  end,
})

return skill
